//
//  CNChangeHostManager.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2020/3/3.
//  Copyright © 2020 CSDN. All rights reserved.
//

#import "CNChangeHostManager.h"
#import "CNBaseNetworkConst.h"

NSString *const ChangeXCaStageNotification = @"ChangeXCaStageNotification";

NSString *const ChangePassPortHostNotification = @"ChangePassPortHostNotification";

NSString *const ChangeNotifyHostNotification = @"ChangeNotifyHostNotification";

NSString *const ChangeWebAPPHostNotification = @"ChangeWebAPPHostNotification";

NSString *const ChangePayHostNotification = @"ChangePayHostNotification";

NSString *const ChangeEduHostNotification = @"ChangeEduHostNotification";

NSString *const ChangeEditorHostNotification = @"ChangeEditorHostNotification";


static CNChangeHostManager * changeURLObject;

@implementation CNChangeHostManager

+ (instancetype)sharedChangeHostObject{
    
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        
        changeURLObject = [[super allocWithZone:NULL] init];
        
        [changeURLObject defaultHost];
        
    });
    
    return changeURLObject;
    
}

- (instancetype)init{
    
    if (self = [super init]) {
        
        //注册通知，用于接收改变Host
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeXCaStage:) name:ChangeXCaStageNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePassPortHost:) name:ChangePassPortHostNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeNotifyHostType:) name:ChangeNotifyHostNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeWebAPPHostType:) name:ChangeWebAPPHostNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePayHostType:) name:ChangePayHostNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeEduHostType:) name:ChangeEduHostNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeEditorHostType:) name:ChangeEditorHostNotification object:nil];
        
        self.kCNALiNewHost = @"https://app-gw.csdn.net";
        self.kCNLiveHost = @"https://app-gw.csdn.net";
        self.kCNLiveManagerHost = @"http://live.csdn.net";
    }
    
    return self;
    
}

-(void)defaultHost
{
    [self xCaStageWithXCaStageType:[CNBaseNetworkConst xCaStageType]];
    [self passPortHostWithPassPortHostType:[CNBaseNetworkConst passPortHostType]];
    [self notifyHostWithNotifyHostType:[CNBaseNetworkConst notifyHostType]];
    [self webAPPHostWithWebAPPHostType:[CNBaseNetworkConst webAPPHostType]];
    [self payHostWithPayHostType:[CNBaseNetworkConst payHostType]];
    [self eduHostWithEduHostType:[CNBaseNetworkConst eduHostType]];
    [self editorHostWithEditorHostType:[CNBaseNetworkConst editorHostType]];
}

- (void)changeXCaStage:(NSNotification *)notification
{
    [self xCaStageWithXCaStageType:[CNBaseNetworkConst xCaStageType]];
}

- (void)changePassPortHost:(NSNotification *)notification
{
    [self passPortHostWithPassPortHostType:[CNBaseNetworkConst passPortHostType]];
}

- (void)changeNotifyHostType:(NSNotification *)notification
{
    [self notifyHostWithNotifyHostType:[CNBaseNetworkConst notifyHostType]];
}

- (void)changeWebAPPHostType:(NSNotification *)notification
{
    [self webAPPHostWithWebAPPHostType:[CNBaseNetworkConst webAPPHostType]];
}

- (void)changePayHostType:(NSNotification *)notification
{
    [self payHostWithPayHostType:[CNBaseNetworkConst payHostType]];
}

- (void)changeEduHostType:(NSNotification *)notification
{
    [self eduHostWithEduHostType:[CNBaseNetworkConst eduHostType]];
}

- (void)changeEditorHostType:(NSNotification *)notification
{
    [self editorHostWithEditorHostType:[CNBaseNetworkConst editorHostType]];
}



-(void)xCaStageWithXCaStageType:(CNXCaStageType)xCaStageType
{
    switch (xCaStageType) {
        case CNXCaStageTypeRelease:
            self.kXCaStage = @"RELEASE";
            break;
            
        case CNXCaStageTypeTest:
            self.kXCaStage = @"TEST";
            break;
            
        case CNXCaStageTypeBeta:
            self.kXCaStage = @"PRE";
            break;
            
        default:
            self.kXCaStage = @"RELEASE";
            break;
    }
}

-(void)passPortHostWithPassPortHostType:(CNPassPortHostType)passPortHostType
{
    switch (passPortHostType) {
        case CNPassPortHostTypeRelease:
            self.kCNPassPortHost = @"https://passport.csdn.net";
            break;
            
        case CNPassPortHostTypeTest:
            self.kCNPassPortHost = @"https://test-passport.csdn.net";
            break;
            
        case CNPassPortHostTypeBeta:
            self.kCNPassPortHost = @"https://passport.csdn.net";
            break;
            
        default:
            self.kCNPassPortHost = @"https://passport.csdn.net";
            break;
    }
}

-(void)notifyHostWithNotifyHostType:(CNNotifyHostType)notifyHostType
{
    switch (notifyHostType) {
        case CNNotifyHostTypeRelease:
            self.kCNNotifyHost = @"https://msg.csdn.net";
            break;
            
        case CNNotifyHostTypeTest:
            self.kCNNotifyHost = @"https://test-notify.csdn.net";
            break;
            
        case CNNotifyHostTypeBeta:
            self.kCNNotifyHost = @"https://msg.csdn.net";
            break;
            
        default:
            self.kCNNotifyHost = @"https://msg.csdn.net";
            break;
    }
}

-(void)webAPPHostWithWebAPPHostType:(CNWebAPPHostType)webAPPHostType
{
    switch (webAPPHostType) {
        case CNWebAPPHostTypeRelease:
            self.kWebAPPHost = @"https://webapp.csdn.net";
            break;
            
        case CNWebAPPHostTypeTest:
            self.kWebAPPHost = @"https://test-webapp.csdn.net";
            break;
            
        case CNWebAPPHostTypeBeta:
            self.kWebAPPHost = @"https://webapp.csdn.net";
            break;
            
        default:
            self.kWebAPPHost = @"https://webapp.csdn.net";
            break;
    }
}

-(void)payHostWithPayHostType:(CNPayHostType)payHostType
{
    switch (payHostType) {
        case CNPayHostTypeRelease:
            self.kCNPayHost = @"https://pay.csdn.net";
            self.kCNMallHost = @"https://mall.csdn.net";
            self.kCNOrderHost = @"https://order.csdn.net";
            break;
            
        case CNPayHostTypeTest:
            self.kCNPayHost = @"https://betapay.csdn.net";
            self.kCNMallHost = @"https://betamall.csdn.net";
            self.kCNOrderHost = @"https://betaorder.csdn.net";
            break;
            
        case CNPayHostTypeBeta:
            self.kCNPayHost = @"https://pre-pay.csdn.net";
            self.kCNMallHost = @"https://pre-mall.csdn.net";
            self.kCNOrderHost = @"https://pre-order.csdn.net";

            break;
            
        default:
            self.kCNPayHost = @"https://pay.csdn.net";
            self.kCNMallHost = @"https://mall.csdn.net";
            self.kCNOrderHost = @"https://order.csdn.net";
            break;
    }
}

-(void)eduHostWithEduHostType:(CNEduHostType)eduHostType
{
    switch (eduHostType) {
        case CNEduHostTypeRelease:
            self.kCNEduHost = @"https://edu.csdn.net";
            break;
            
        case CNEduHostTypeTest:
            self.kCNEduHost = @"https://betaedu.csdn.net";
            break;
            
        case CNEduHostTypeBeta:
            self.kCNEduHost = @"https://edu.csdn.net";
            break;
            
        default:
            self.kCNEduHost = @"https://edu.csdn.net";
            break;
    }
}

-(void)editorHostWithEditorHostType:(CNEditorHostType)editorHostType
{
    switch (editorHostType) {
        case CNEditorHostTypeRelease:
            self.kEditorHost = @"https://editor.csdn.net";
            break;
            
        case CNEditorHostTypeTest:
            self.kEditorHost = @"https://test-editor.csdn.net";
            break;
            
        case CNEditorHostTypeBeta:
            self.kEditorHost = @"https://editor.csdn.net";
            break;
            
        default:
            self.kEditorHost = @"https://editor.csdn.net";
            break;
    }
}



- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}



@end
